
package com.example.demo.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.pojo.Link_1;
import com.example.demo.pojo.Sheet;
import com.example.demo.pojo.User;
import com.example.demo.service.SheetService;

@Controller
@RequestMapping("/sheet")
public class SheetAction {
	@Autowired
	private SheetService sheetService;
	@RequestMapping("/shouye")
	public String getList(Model model) {
		List<Sheet> getlist=sheetService.getList();
		model.addAttribute("getlist",getlist);
		return "home";
	}
	@RequestMapping("/huayu")
	public String getList1(Model model) {
		List<Sheet> getlist1=sheetService.getList1();
		model.addAttribute("huayu",getlist1);
		return "sheet2";
	}
	@RequestMapping("/yueyu")
	public String getList2(Model model) {
		List<Sheet> getlist2=sheetService.getList2();
		model.addAttribute("yueyu",getlist2);
		return "sheet3";
	}
	
	@RequestMapping("/rihan")
	public String getList3(Model model) {
		List<Sheet> getlist3=sheetService.getList3();
		model.addAttribute("rihan",getlist3);
		return "sheet4";
	}
	
	@RequestMapping("/oumei")
	public String getList4(Model model) {
		List<Sheet> getlist4=sheetService.getList4();
		model.addAttribute("oumei",getlist4);
		return "sheet5";
	}
	@RequestMapping("/getGedanList")
	public String getGedanList(Model model) {
		List<Sheet> getgedanList=sheetService.getGedanList();
		model.addAttribute("getgedanlist", getgedanList);
		return "/user/ht_gedan";
	}
	@RequestMapping("/deleteLink")
	public String deleteLink(Link_1 link,Model model) {
		boolean f=sheetService.deleteSheet(link);
		if(f) {
			return "forward:/sheet/getGedanList";
		}
		else {
			model.addAttribute("result","no");
			model.addAttribute("msg","删除失败");
			return "/user/result";	
		}
	}

	//展示柱状图
    @RequestMapping( "/show")
    @ResponseBody
    public List<Sheet> show() {
        List<Sheet> sheetist=sheetService.sheetList();
        return sheetist;

    }

	@RequestMapping("/getListDetail")
	public String getListDetail(Model model,int sheet_id) {
		List<Sheet> getListDetail=sheetService.getListDetail(sheet_id);
		model.addAttribute("getListDetail", getListDetail);
		return "sheet_list";
	}
	@RequestMapping("/searchSheetList")
	public String searchUserList(Model model,String sheet_name,String  labal) {
		List<Sheet> getgedanList=sheetService.searchSheetList(sheet_name, labal);
		model.addAttribute("getgedanlist",getgedanList);
		return "/user/ht_gedan";
	}
	@RequestMapping("/addSheet")
	public String addSheet(Sheet sheet,Model model) {
		int i=sheetService.addSheet(sheet);
		if(i==0) {
			model.addAttribute("result","yes");
			model.addAttribute("msg","恭喜您，注册成功！");
		}else if(i==1) {
			model.addAttribute("result","no");
			model.addAttribute("msg","恭喜您，该用户也注册，请更换！");
		}else if(i==2) {
			model.addAttribute("result","no");
			model.addAttribute("msg","对不起，注册失败！");
		}
		return"forward:/sheet/getGedanList";
	}

}


